package com.ruoyi.smart.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.smart.domain.SmartProcess;
import com.ruoyi.smart.service.ISmartProcessService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工序Controller
 * 
 * @author minwei
 * @date 2022-04-19
 */
//@Api("工序")
@RestController
@RequestMapping("/smart/process")
public class SmartProcessController extends BaseController
{
    @Autowired
    private ISmartProcessService smartProcessService;

    /**
     * 查询工序列表
     */
    @PreAuthorize("@ss.hasPermi('smart:process:list')")
    @GetMapping("/list")
    //@ApiOperation("查询工序列表")
    public TableDataInfo list(SmartProcess smartProcess)
    {
        startPage();
        List<SmartProcess> list = smartProcessService.selectSmartProcessList(smartProcess);
        return getDataTable(list);
    }

    /**
     * 导出工序列表
     */
    @PreAuthorize("@ss.hasPermi('smart:process:export')")
    @Log(title = "工序", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmartProcess smartProcess)
    {
        List<SmartProcess> list = smartProcessService.selectSmartProcessList(smartProcess);
        ExcelUtil<SmartProcess> util = new ExcelUtil<SmartProcess>(SmartProcess.class);
        util.exportExcel(response, list, "工序数据");
    }

    /**
     * 获取工序详细信息
     */
    //@ApiOperation("获取工序详细信息")
    @PreAuthorize("@ss.hasPermi('smart:process:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smartProcessService.selectSmartProcessById(id));
    }

    /**
     * 新增工序
     */
    @PreAuthorize("@ss.hasPermi('smart:process:add')")
    @Log(title = "工序", businessType = BusinessType.INSERT)
    @PostMapping
    //@ApiOperation("新增工序")
    public AjaxResult add(@RequestBody SmartProcess smartProcess)
    {
        return toAjax(smartProcessService.insertSmartProcess(smartProcess));
    }

    /**
     * 修改工序
     */
    //@ApiOperation("修改工序")
    @PreAuthorize("@ss.hasPermi('smart:process:edit')")
    @Log(title = "工序", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmartProcess smartProcess)
    {
        return toAjax(smartProcessService.updateSmartProcess(smartProcess));
    }

    /**
     * 删除工序
     */
    //@ApiOperation("删除工序")
    @PreAuthorize("@ss.hasPermi('smart:process:remove')")
    @Log(title = "工序", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smartProcessService.deleteSmartProcessByIds(ids));
    }
}
